package part04_观察者模式.p01_传统方法;

/** 天气数据（核心类）
 * @ClassName: WeatherData
 * @Author: AllenSun
 * @Date: 2019/12/6 19:26
 */
public class WeatherData {
    private float temperature;
    private float pressure;
    private float humidity;
    //WeatherData里的数据是最新的数据，CurrentCondition里是还没更新的旧数据
    private CurrentCondition currentCondition;

    //构造器，初始化时自动实例化CurrentCondition类对象
    public WeatherData(CurrentCondition currentCondition){
        this.currentCondition=currentCondition;
    }

    //外界可以通过这三个get方法获取属性的值
    public float getTemperature() {
        return temperature;
    }

    public float getPressure() {
        return pressure;
    }

    public float getHumidity() {
        return humidity;
    }

    public void setData(float temperature, float pressure, float humidity){
        this.temperature=temperature;
        this.pressure=pressure;
        this.humidity=humidity;
        //当有数据更新时，就会主动调用方法来更新观察者currentCondition里的数据
        dataChange();
    }

    //currentCondition对象调用update方法来更新数据
    public void dataChange(){
        currentCondition.update(getTemperature(),getPressure(),getHumidity());
    }
}
